//
//  PageFlowMenuTableViewCell_Picker.m
//  MKUITestApp
//
//  Created by 苏尚进 on 2020/10/9.
//  Copyright © 2020 moon. All rights reserved.
//

#import "PageFlowMenuTableViewCell_Picker.h"
#import "MenuCollectionViewCell_OnlyImage.h"
@implementation PageFlowMenuTableViewCell_Picker

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self=[super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.pageFlowLayout.interitemSpacing = 10;
        self.pageFlowLayout.enableCycleScroll = YES;
        
//        MKUICollectionViewPagePickerFlowLayout *pickerLayout = (MKUICollectionViewPagePickerFlowLayout *)self.pageFlowLayout;
//        pickerLayout.scaleRange = MKCGRangeMake(1.25, 0.5);
        
        self.collectionView.model.forwardDelegate = self;
        MKUILayoutConstraintItemWrapper *w1 = [MKUILayoutConstraintItemWrapper wrapItem:self.collectionView sizeThatFitsBlock:^CGSize(MKUILayoutConstraintItemWrapper * _Nonnull wrapper, CGSize size, BOOL resizeItems) {
            return CGSizeMake(size.width, 100);
        }];
        //
        self.flowlayout = [[MKUIFlowLayoutConstraint alloc] initWithItems:@[w1,self.pageControl] constraintParam:(MKUIFlowLayoutConstraintParam_V_C_C) contentInsets:UIEdgeInsetsZero interitemSpacing:5];
        //
        self.alignLine = [[UIView alloc] init];
        [self.myContentView addSubview:self.alignLine];
        self.alignLine.backgroundColor = [UIColor systemRedColor];
    }
    return self;
}
+ (Class)menuCellClass{
    return [MenuCollectionViewCell_OnlyImage class];
}
+ (Class)pageFlowLayoutClass{
    return [MKUICollectionViewPagePickerFlowLayout class];
}
- (UIScrollViewDecelerationRate)defalutUIScrollViewDecelerationRate{
    return UIScrollViewDecelerationRateNormal;
}
- (void)layoutMyContentView{
    [super layoutMyContentView];
    CGRect bounds = self.myContentView.bounds;
    self.flowlayout.bounds = bounds;
    [self.flowlayout layoutItemsWithResizeItems:YES];
    {
        CGRect bounds = self.collectionView.frame;
        MKCGRectAlignment align = self.pageFlowLayout.itemAlignment;
        
        MKCGAxis X = self.pageFlowLayout.scrollAxis;
        MKCGAxis Y = MKCGAxisReverse(X);
        CGRect f1 = bounds;
        MKCGRectSetLength(&f1, Y, 2);
        
        UIEdgeInsets sectionInsets = [self.pageFlowLayout insetForSectionAtIndex:0];
        CGRect f2 = UIEdgeInsetsInsetRect(bounds, sectionInsets);
        MKCGRectAlignToRect(&f1, Y, align, f2);
        
        self.alignLine.frame = f1;
    }
}
- (CGSize)sizeMyContentViewThatFits:(CGSize)size{
    return [self.flowlayout sizeThatFits:size resizeItems:YES];
}
- (CGSize)collectionView:(UICollectionView *)collectionView pageFlowLayout:(MKUICollectionViewPageFlowLayout *)collectionViewLayout itemSizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    CGRect bounds = collectionView.bounds;
    CGSize size = bounds.size;
    size.width = size.height = 44;
    return size;
}
@end
